//
//  LoginView.m
//  Village
//
//  Created by 程虎 on 2017/9/12.
//  Copyright © 2017年 程虎. All rights reserved.
//

#import "LoginView.h"
#import <UIButton+WebCache.h>
#import "JKCountDownButton.h"
#import "LoginItemVew1.h"
#import "LoginItemVew.h"
#import "LoginHttpTools.h"
#import "MineController.h"
#import "LRTableController.h"
#import "DESCript.h"
@interface LoginView()
@property (nonatomic, assign) NSInteger indexType;//0 账号登录 1 手机号登录
@property (nonatomic, strong) UIButton *desBtn;
@property (nonatomic, strong) UIButton *registerBtn;
@property (nonatomic, strong) UIButton *forgetBtn;
@property (nonatomic, strong) UIButton *closeBtn;
@property (nonatomic, strong) UIButton *loginBtn;
@property (nonatomic, strong) JKCountDownButton *codeButton;
@property (nonatomic, strong) UIScrollView *scoll;
@property (nonatomic, strong) UIViewController *showVC;
@end

@implementation LoginView

- (instancetype)initWithShowVC:(UIViewController *)showVC
{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.showVC = showVC;
        self.indexType = 0;
        [self set_UI];
    }
    return self;
}

- (void)set_UI
{
    NSArray *array = @[@{@"des":@"账号",@"name":@"请输入账号"},@{@"des":@"密码",@"name":@"请输入密码"}];
    NSArray *array1 = @[@{@"des":@"手机号",@"name":@"请输入手机号"},@{@"des":@"验证码",@"name":@"请输入验证码"},@{@"des":@"短信验证码",@"name":@"请输入短信验证码"}];
    
    self.closeBtn = [[Tools shareInstance] creat_Button:@"" Color:[UIColor whiteColor] BackColors:[UIColor clearColor] Font:16 tag:200];
    [self.closeBtn setImage:[UIImage imageNamed:@"close_login"] forState:UIControlStateNormal];
    [self.closeBtn addTarget:self action:@selector(otherBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    self.forgetBtn = [[Tools shareInstance] creat_Button:@"忘记密码" Color:[Util colorWithHexString:@"#999999"] BackColors:[UIColor whiteColor] Font:14 tag:201];
    [self.forgetBtn addTarget:self action:@selector(otherBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    self.registerBtn = [[Tools shareInstance] creat_Button:@"注册账号" Color:[Util colorWithHexString:@"#ff0000"] BackColors:[UIColor whiteColor] Font:14 tag:202];
    [self.registerBtn addTarget:self action:@selector(otherBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    self.scoll = [UIScrollView new];
    self.scoll.scrollEnabled = NO;
    self.scoll.bounces = YES;
    self.scoll.pagingEnabled = YES;
    self.scoll.showsVerticalScrollIndicator = NO;
    self.scoll.showsHorizontalScrollIndicator = NO;
    self.scoll.contentSize = CGSizeMake(SCREEN_W * 2, 300);
    
    UIView *views = [self creatUserNameView:array Types:0];
    views.frame =CGRectMake(0, 0, SCREEN_W, 300);
    UIView *views1 = [self creatUserNameView:array1 Types:1];
    views1.frame =CGRectMake(SCREEN_W, 0, SCREEN_W, 300);
//    UIView *views = [Tools creatUserView];
//    views.frame =CGRectMake(0, 0, SCREEN_W, 300);
//    UIView *views1 = [Tools creatPhoneView];
//    views1.frame =CGRectMake(SCREEN_W, 0, SCREEN_W, 300);
//    LoginItemVew *views = [[LoginItemVew alloc] initWithItemsWithTypes:0];
//    views.scrollBlock = ^(NSInteger index) {
//        if (index == 204) {
//            self.indexType = 1;
//        }
//        else {
//            self.indexType = 0;
//        }
//        [self.scoll scrollRectToVisible:CGRectMake(self.indexType * SCREEN_W, 0, SCREEN_W,300) animated:YES];
//    };
//    LoginItemVew *views1 = [[LoginItemVew alloc] initWithItemsWithTypes:0];
//
    UIView *typeView = [self  creatThirdPartyView];
    
    [self.scoll sd_addSubviews:@[views,views1]];
    [self sd_addSubviews:@[self.closeBtn,self.forgetBtn,self.registerBtn,self.scoll,typeView]];
    
    CGFloat left = 30;
    CGFloat top = 45;
    
    self.closeBtn.sd_layout
    .leftSpaceToView(self, left)
    .topSpaceToView(self, top)
    .widthIs(16.5)
    .heightIs(16.5);
    
    self.registerBtn.sd_layout
    .rightSpaceToView(self, left)
    .centerYEqualToView(self.closeBtn)
    .widthIs(70)
    .heightIs(40);
    
    self.forgetBtn.sd_layout
    .rightSpaceToView(self.registerBtn, 10)
    .centerYEqualToView(self.registerBtn)
    .widthRatioToView(self.registerBtn, 1)
    .heightRatioToView(self.registerBtn, 1);
    
    self.scoll.sd_layout
    .leftSpaceToView(self, 0)
    .topSpaceToView(self.closeBtn, iPhone5 ? 40 : 80)
    .rightSpaceToView(self, 0)
    .heightIs(300);
    
    typeView.sd_layout
    .rightSpaceToView(self, 0)
    .leftSpaceToView(self, 0)
    .bottomSpaceToView(self, 0);
    
}
#pragma mark - 第三方登录
//---------------------------------------------------------------------------------------
- (UIView *)creatThirdPartyView
{
    UIView *bkView = [UIView new];
    bkView.backgroundColor = [UIColor whiteColor];
    
    NSArray *dataAry = @[@{@"title":@"微信登录",@"img":@"wx_login"},
                         @{@"title":@"QQ登录",@"img":@"QQ_login"}];
    
    UIView *noticeView = [self creatNoticeView];
    UIView *typeView = [self creatLoginTypeView:dataAry];
    [bkView sd_addSubviews:@[noticeView,typeView]];
    
    noticeView.sd_layout
    .leftSpaceToView(bkView, 0)
    .topSpaceToView(bkView, 0)
    .rightSpaceToView(bkView, 0);
    
    typeView.sd_layout
    .centerXEqualToView(bkView)
    .topSpaceToView(noticeView, 10)
    .widthIs((dataAry.count + 1) * 70);
    
    [bkView setupAutoHeightWithBottomView:typeView bottomMargin:50];
    
    return bkView;
}

- (UIView *)creatNoticeView
{
    UIView *views = [UIView new];
    views.backgroundColor = [UIColor whiteColor];
    
    UIImageView *line = [UIImageView new];
    line.backgroundColor = K_LineColor;
    
    UIImageView *line1 = [UIImageView new];
    line1.backgroundColor = K_LineColor;
    
    UILabel *lab = [[Tools shareInstance] creat_Label:@"其他方式登录" Color:[Util colorWithHexString:@"999999"] Font:14 tag:-1 Alignment:1 Lines:1];
    
    [views sd_addSubviews:@[line,lab,line1]];
    
    lab.sd_layout
    .topSpaceToView(views, 0)
    .centerXEqualToView(views)
    .heightIs(13);
    
    line.sd_layout
    .leftSpaceToView(views, 30)
    .centerYEqualToView(lab)
    .rightSpaceToView(lab, 30)
    .heightIs(0.5);
    
    line1.sd_layout
    .leftSpaceToView(lab, 16)
    .centerYEqualToView(lab)
    .rightSpaceToView(views, 30)
    .heightIs(0.5);
    
    [lab setSingleLineAutoResizeWithMaxWidth:100];
    
    [views setupAutoHeightWithBottomView:lab bottomMargin:0];
    
    return views;
}
- (UIView *)creatLoginTypeView:(NSArray *)array
{
    UIView *bkView = [UIView new];
    bkView.backgroundColor = [UIColor whiteColor];
    
    NSMutableArray *temp = [NSMutableArray array];
    for (int i = 0; i < array.count; i++) {
        NSDictionary *dict = array[i];
        UIView *views = [self creat_view:dict[@"img"] titles:dict[@"title"] Tag:i + 300];
        [bkView addSubview:views];
        [temp addObject:views];
        views.sd_layout.heightIs(71);
    }
    [bkView setupAutoWidthFlowItems:[temp copy] withPerRowItemsCount:array.count verticalMargin:0 horizontalMargin:50 verticalEdgeInset:0 horizontalEdgeInset:0];
    
    return bkView;
}

- (UIView *)creat_view:(NSString *)img titles:(NSString *)titles Tag:(NSInteger)tags
{
    UIView *backViews = [UIView new];
    backViews.backgroundColor = [UIColor whiteColor];
    
    UIImageView *images = [UIImageView new];
    images.backgroundColor = [UIColor whiteColor];
    images.image = [UIImage imageNamed:img];
    
    UILabel *lab = [[Tools shareInstance] creat_Label:titles Color:[Util colorWithHexString:@"#666666"] Font:13 tag:-1 Alignment:1 Lines:1];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.backgroundColor = [UIColor clearColor];
    btn.tag = tags;
    [btn addTarget:self action:@selector(itemsClick:) forControlEvents:UIControlEventTouchUpInside];
    [backViews sd_addSubviews:@[images,lab,btn]];
    
    CGFloat width = 50;
    CGFloat height = 50;
    CGFloat margin = 9.5;
    
    images.sd_layout
    .centerXEqualToView(backViews)
    .topSpaceToView(backViews, 15)
    .widthIs(width)
    .heightIs(height);
    
    lab.sd_layout
    .topSpaceToView(images, margin)
    .centerYEqualToView(images)
    .widthRatioToView(backViews, 1)
    .heightIs(11.5);
    
    btn.sd_layout.spaceToSuperView(UIEdgeInsetsZero);
    
    return backViews;
}
//---------------------------------------------------------------------------------------
#pragma mark - 点击事件处理

#pragma mark - btn点击事件
- (void)otherBtnClick:(UIButton *)buttons
{
    if (buttons.tag == 200) {//关闭
        [self.showVC dismissViewControllerAnimated:YES completion:nil];
//        //取出根视图控制器
        
        //代理跳转
//        if ([self.delegate respondsToSelector:@selector(goToController)]) {
//            [self.delegate goToController];
//        }

    }
    else if (buttons.tag == 201 || buttons.tag == 202) {//忘记密码
        [self forgetAndRegister:buttons.tag];
    }
    else if (buttons.tag == 203) {//账号登录
        [self userLogin];
    }
    else if (buttons.tag == 204) {//使用短信验证登录
        if (self.indexType == 0) {
            self.indexType = 1;
        }
        else {
            self.indexType = 0;
        }
        [self.scoll scrollRectToVisible:CGRectMake(self.indexType * SCREEN_W, 0, SCREEN_W,300) animated:YES];
    }
    else if (buttons.tag == 205) {//是否密码可见
        LSLog(@"手机号登录");
    }
    else {
    }
}

#pragma mark - 忘记密码、账号注册
- (void)forgetAndRegister:(NSInteger )index
{
    NSString *types = index == 201 ? @"1" : @"2";
    WeakSelf(weakSelf);
    [Tools ToNextName:@"PasswordViewController" Params:types CurrentVC:self.showVC Completion:^(id obj) {
        AccountModel *model = (AccountModel *)obj;
        UITextField *txtfield = [weakSelf viewWithTag:150 + self.indexType * 3];
        txtfield.text = weakSelf.indexType == 0 ? model.account : model.phone;
    }];
}

#pragma mark - 登录
- (void)userLogin
{
    [self requestTologin];
}

- (void)requestTologin
{
    UITextField *txtfield = [self viewWithTag:150 + self.indexType * 3];
    UITextField *txtfield1 = [self viewWithTag:151 + self.indexType * 3];
    UITextField *txtfield2 = [self viewWithTag:152 + self.indexType * 3];
    
//    NSString *utf8Str = @"a123456";
//    NSString * encodedString = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL,(CFStringRef)utf8Str,NULL,(CFStringRef)@"s(p7~;j^",

//                                                                             kCFStringEncodingUTF8 ));
    NSString *password = txtfield1.text;
    NSString *pass = [DESCript encrypt:password encryptOrDecrypt:kCCEncrypt key:passkey];
    
    if (!txtfield.text.length) {
        [MBProgressHUD showError:self.indexType == 0 ? @"请输入您的账号！" : @"请输入您的手机号！" toView:self];
    }
    else if (self.indexType == 0 ? !txtfield1.text.length : !txtfield2.text.length ) {
        [MBProgressHUD showError:self.indexType == 0 ? @"请输入您的密码！" : @"请输入您的短信验证码！" toView:self];
    }
    else if (![Tools checkPhoneNORationality:self.indexType == 0 ? @"15897537048" : txtfield.text]) {
        [MBProgressHUD showError:@"请输入正确的手机号码！" toView:self];
    }
    else {
        WeakSelf(weakSelf);
        [MBProgressHUD showMessage:@"正在登录..." toView:self];
        [LoginHttpTools LoginWithName:txtfield.text WithPW:self.indexType == 0 ? pass : txtfield2.text WithTypes:self.indexType Success:^(NSDictionary *valueDict) {
                [MBProgressHUD hideHUDForView:weakSelf];
                //保存用户数据
                [[Globle getInstance] saveAccountInfo:valueDict[@"data"]];
                //置空用户临时数据
                [Globle getInstance].visitorWXID = nil;
                [Globle getInstance].visitorQQID = nil;
                [Globle getInstance].visitorName = nil;
                [Globle getInstance].visitorIcon = nil;
                [MBProgressHUD showSuccess:valueDict[@"message"]  toView:self Completion:^{
                [[NSNotificationCenter  defaultCenter] postNotificationName:RefreshLoginInfo object:nil];
                [weakSelf.showVC dismissViewControllerAnimated:YES completion:nil];
//                if ([self.delegate respondsToSelector:@selector(goToController)]) {
//                        [self.delegate goToController];
//                    }
            }];
        } failure:^(NSString *error) {
            [MBProgressHUD hideHUDForView:weakSelf];
            if ([error containsString:@"用户不存在"]) {
                [MBProgressHUD showError:@"该手机号未注册，请先注册" toView:weakSelf];
            }
            else {
                [MBProgressHUD showError:error toView:weakSelf];
            }
        }];
    }
}

#pragma mark - 第三方登录
- (void)itemsClick:(UIButton *)buttons
{
    if (buttons.tag == 300) {//微信
        [[ShareFunction shareInstance] loginOtherWaysWithType:0 ToController:self.showVC];
    }
    else {
        [[ShareFunction shareInstance] loginOtherWaysWithType:1 ToController:self.showVC];
    }
    WeakSelf(weakSelf);
    [ShareFunction shareInstance].loginBlock = ^(UMSocialUserInfoResponse *resp) {
        LSLog(@"第三方登录 ------ %@",resp.name);
        //判断如果已绑定 置空临时数据 
        [Globle getInstance].visitorWXID = buttons.tag == 300 ? resp.openid : @"";
        [Globle getInstance].visitorQQID = buttons.tag == 301 ? resp.openid : @"";
        [Globle getInstance].visitorName = resp.name;
        [Globle getInstance].visitorIcon = resp.iconurl;
        [weakSelf thirdPartyLogin];
    };
}

- (void)thirdPartyLogin
{
    WeakSelf(weakSelf);
    [MBProgressHUD showMessage:@"正在登录..." toView:self];
    [LoginHttpTools LoginWithThirdPartyWithQQID:[Globle getInstance].visitorQQID WithWXID:[Globle getInstance].visitorWXID Success:^(NSDictionary *valueDict) {
        [MBProgressHUD hideHUDForView:weakSelf];
        //保存用户数据
        [[Globle getInstance] saveAccountInfo:valueDict[@"data"]];
        //置空用户临时数据
        [Globle getInstance].visitorWXID = nil;
        [Globle getInstance].visitorQQID = nil;
        [Globle getInstance].visitorName = nil;
        [Globle getInstance].visitorIcon = nil;
        [[NSNotificationCenter  defaultCenter] postNotificationName:RefreshLoginInfo object:nil];
        [weakSelf.showVC dismissViewControllerAnimated:YES completion:nil];
    } failure:^(NSString *error) {
        [MBProgressHUD hideHUDForView:weakSelf];
        [[NSNotificationCenter  defaultCenter] postNotificationName:RefreshLoginInfo object:nil];
        [weakSelf.showVC dismissViewControllerAnimated:YES completion:nil];
    }];
}

#pragma mark - 发送请求
- (void)loginSendVificationWithBtn:(JKCountDownButton *)sender
{
    UITextField *txtfield = [self viewWithTag:150 + self.indexType * 3];
    UITextField *txtfield1 = [self viewWithTag:151 + self.indexType * 3];
    UITextField *txtfield2 = [self viewWithTag:152 + self.indexType * 3];
    if (!txtfield.text.length) {
        [MBProgressHUD showError:@"请输入手机号码！" toView:self];
    }
    else if (!txtfield1.text.length) {
        [MBProgressHUD showError:@"请输入图片验证码！" toView:self];
    }
    else if (![Tools checkPhoneNORationality:txtfield.text]) {
        [MBProgressHUD showError:@"请输入正确的手机号码！" toView:self];
    }
    else {
        NSMutableDictionary *bean = [NSMutableDictionary dictionary];
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        [bean setValue:dict forKey:@"entitybean"];
        [dict setObject:txtfield.text forKey:@"phone"];
        [dict setObject:txtfield1.text forKey:@"imagecode"];
        
        WeakSelf(weakSelf);
        [NetRequestClass Post:RegisterGetMSGCodeURL Parameters:bean success:^(id result) {
            [MBProgressHUD hideHUDForView:self];
            [MBProgressHUD showSuccess:result[@"message"] toView:self Completion:^{
                [weakSelf startBtnCount:sender];
            }];
            LSLog(@"msg -----  %@",result);
            txtfield2.text = result[@"data"];
        } failure:^(id valueCode, id error) {
            [MBProgressHUD hideHUDForView:self];
            [MBProgressHUD showError:error toView:self];
            [self.codeButton stopCountDown];
        }];
    }
}

- (void)startBtnCount:(JKCountDownButton *)sender
{
    [sender startCountDownWithSecond:60];
    
    [sender countDownChanging:^NSString *(JKCountDownButton *countDownButton, NSUInteger second) {
        sender.enabled = NO;
        NSString *title = [NSString stringWithFormat:@"%zds",second];
        return title;
    }];
    
    [sender countDownFinished:^NSString *(JKCountDownButton *countDownButton, NSUInteger second) {
        countDownButton.enabled = YES;
        return @"获取验证码";
        
    }];
}


#pragma mark - 是否显示密码
- (void)showTextEntry:(UIButton *)buttons
{
    if (buttons.tag == 30) {
        buttons.selected = !buttons.selected;
        [buttons setImage:[UIImage imageNamed:buttons.selected == YES ? @"unopen" : @"open"] forState:UIControlStateNormal];
        UITextField *txtfield = [self viewWithTag:151 + self.indexType * 3];
        txtfield.secureTextEntry = buttons.selected;
    }
    else {
        dispatch_async(dispatch_get_global_queue(0, 0), ^{
            UIImage *imgs = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:IMGCodeURL]]];
            dispatch_async(dispatch_get_main_queue(), ^{
                [buttons setBackgroundImage:imgs forState:UIControlStateNormal];
            });
        });
    }
}


#pragma mark - UI 布局

#pragma mark - 账号登录view
- (UIView *)creatUserNameView:(NSArray *)arrays Types:(NSInteger )index
{
    UIView *bkViews = [UIView new];
    UIView *views1 = [Tools creatColumView:arrays[0] Tags:150 + index * 3];
    UIView *views2 = [Tools creatColumView:arrays[1] Tags:151 + index * 3];
    UIView *views3 = [UIView new];
    
    UIButton *showPWBtn = [[Tools shareInstance] creat_Button:@"" Color:[UIColor blackColor] BackColors:[UIColor whiteColor] Font:16 tag:205];
    showPWBtn.frame = CGRectMake(0, 1, 30, 28);
    UITextField *txtfield1 = [views2 viewWithTag:151 + index * 3];
    
    if (index == 0) {
        showPWBtn.tag = 30;
        [showPWBtn addTarget:self action:@selector(showTextEntry:) forControlEvents:UIControlEventTouchUpInside];
        [showPWBtn setImage:[UIImage imageNamed:@"unopen"] forState:UIControlStateNormal];
        txtfield1.secureTextEntry = YES;
        txtfield1.rightView = showPWBtn;
        txtfield1.rightViewMode = UITextFieldViewModeAlways;
    }
    else {
        views3 = [Tools creatColumView:arrays[2] Tags:152 + index * 3];
        UITextField *txtfield2 = [views3 viewWithTag:152 + index * 3];
        showPWBtn.tag = 40;
        [showPWBtn addTarget:self action:@selector(showTextEntry:) forControlEvents:UIControlEventTouchUpInside];
        [showPWBtn setBackgroundImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:IMGCodeURL]]] forState:UIControlStateNormal];
        showPWBtn.frame = CGRectMake(0, 1, iPhone5 == YES ? 90 : 100, 28);
        txtfield1.rightView = showPWBtn;
        txtfield1.rightViewMode = UITextFieldViewModeAlways;
        
        self.codeButton = [JKCountDownButton buttonWithType:UIButtonTypeCustom];
        self.codeButton.frame = CGRectMake(0, 0, iPhone5 == YES ? 90 : 100, 30);
        self.codeButton.titleLabel.font = LRFont(12);
        self.codeButton.backgroundColor = [UIColor whiteColor];
        [self.codeButton setTitle:@"获取验证码" forState:UIControlStateNormal];
        [self.codeButton setTitleColor:[Util colorWithHexString:@"#f54f33"] forState:UIControlStateNormal];
        LRViewRadius(self.codeButton, 3, 0.5, [Util colorWithHexString:@"#f54f33"]);
        self.codeButton.titleLabel.font = [UIFont systemFontOfSize:16];
        txtfield2.rightView = self.codeButton;
        txtfield2.rightViewMode = UITextFieldViewModeAlways;
        
        __weak typeof (self) weakSelf = self;
        [self.codeButton countDownButtonHandler:^(JKCountDownButton *sender, NSInteger tag) {
            UITextField *phoneTxt = [self viewWithTag:150 + self.indexType * 3];
            if (![Tools checkPhoneNORationality:phoneTxt.text])
            {
                [MBProgressHUD showError:@"请输入正确的手机号！" toView:self];
                [weakSelf.codeButton stopCountDown];
            }
            else {
                
                [weakSelf loginSendVificationWithBtn:sender];
            }
            
        }];
    }
    
    self.loginBtn = [[Tools shareInstance] creat_Button:@"登录" Color:[UIColor whiteColor] BackColors:KRedColors Font:18 tag:203];
    [self.loginBtn addTarget:self action:@selector(otherBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    LRViewRadius(self.loginBtn, 5, 0.5, [UIColor clearColor]);
    self.desBtn = [[Tools shareInstance] creat_Button:index == 0 ? @"使用短信验证码登录" : @"使用账号、密码登录" Color:[Util colorWithHexString:@"#ff0000"] BackColors:[UIColor whiteColor] Font:14 tag:204];
    [self.desBtn addTarget:self action:@selector(otherBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [bkViews sd_addSubviews:@[views1,views2,views3,self.loginBtn,self.desBtn]];
    
    CGFloat left = iPhone5 == YES ? 15 : 30;
    
    views1.sd_layout
    .leftSpaceToView(bkViews, 0)
    .topSpaceToView(bkViews, 0)
    .rightSpaceToView(bkViews, 0);
    
    views2.sd_layout
    .leftSpaceToView(bkViews, 0)
    .topSpaceToView(views1, 0)
    .rightSpaceToView(bkViews, 0);
    
    if (index == 0) {
        self.loginBtn.sd_layout
        .leftSpaceToView(bkViews, left)
        .topSpaceToView(views2, 20)
        .rightSpaceToView(bkViews, left)
        .heightIs(45);
    }
    else {
        views3.sd_layout
        .leftSpaceToView(bkViews, 0)
        .topSpaceToView(views2, 0)
        .rightSpaceToView(bkViews, 0);
        
        self.loginBtn.sd_layout
        .leftSpaceToView(bkViews, left)
        .topSpaceToView(views3, 20)
        .rightSpaceToView(bkViews, left)
        .heightIs(45);
    }
    
    self.desBtn.sd_layout
    .topSpaceToView(self.loginBtn, 20)
    .leftEqualToView(self.loginBtn)
    .rightEqualToView(self.loginBtn)
    .heightIs(40);
    [bkViews setupAutoHeightWithBottomView:self.desBtn bottomMargin:0];
    
    return bkViews;
}

@end
